package version2024.medium;

import java.util.Scanner;

/**
 * @author sunhl
 * @Description: HJ69 矩阵乘法  数组
 * @Date: created in 2025/1/4 星期六 16:19
 * @Modified By:
 */
public class HJ69_MatrixMultiplication {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            // 获取入参, x, y, z
            int x = in.nextInt();
            int y = in.nextInt();
            int z = in.nextInt();
            // 根据入参构建两个数组矩阵
            int[][] mat1 = new int[x][y];
            int[][] mat2 = new int[y][z];

            // 向矩阵内填入参数
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                    mat1[i][j] = in.nextInt();
                }
            }
            for (int i = 0; i < y; i++) {
                for (int j = 0; j < z; j++) {
                    mat2[i][j] = in.nextInt();
                }
            }

            // 两个矩阵相乘
            int[][] res = mul(mat1, mat2);

            // 打印相乘后的结果
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < z; j++) {
                    System.out.print(res[i][j] + " ");
                }
                System.out.println();
            }
        }
    }

    public static int[][] mul(int[][] mat1, int[][] mat2) {
        int x = mat1.length;
        int y = mat1[0].length;
        int z = mat2[0].length;

        int[][] res = new int[x][z];
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < z; j++) {
                for (int k = 0; k < y; k++) {
                    res[i][j] += mat1[i][k] * mat2[k][j];
                }
            }
        }

        return res;
    }
}
